StatsD Flask

Python application
  1. In my python file app.py am using the library flask_statsdclient
  2. I initialize Flask object called app.
  3. I initialize StatsD client object calling this call - StatsDClient(app)
  4. I setup STATSD_HOST=localhost, STATSD_PORT=8125, STATSD_PREFIX=statsd
  5. When I am creating an API endpoint, example create_user I increment the statsd metric counter with the syntax - c.incr('register_user')
Let's see how the statsd sends metrics from app.py to AWS CloudWatch
  1. We have a file called - amazon-cloudwatch-agent.json
  2. This file includes what needs to be collected from the application - logs, metrics
  3. Since we are interested in metrics, which metrics are we collecting from statsd?
  4. Json example here
  5. Along with this, we are specifying the statsd config - port, collection interval and aggregation interval
  6. This file needs to be a specific location for the cloudwatch agent to read